<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册页面</title>
    <style>
        html,body{
            width: 100%;
            height: 100%;
        }
        *{margin: 0;padding: 0;}
        body{
            display: flex;
            justify-content: center;
            align-items: center;
        }
        div{
            text-align: center;
            padding: 50px;
            background-color: #999;
        }
        div p{
            margin: 50px 0;
        }
        div input{
            width: 500px;
            height: 50px;
            text-indent: 20px;
        }
        div button{
            width: 200px;
            height: 50px;
            font-size: 20px;
        }
    </style>
</head>
<body>
    <div>
        <h1>注册</h1>
        <p>账号：<input class="account" type="text" placeholder="请输入账号（11位手机号码）"></p>
        <p>密码：<input class="password" type="password" placeholder="请输入密码"></p>
        <button>立即注册</button>
    </div>

    <script src="./http.js"></script>
    <script>

        document.querySelector('button').onclick = function(){

            // 获取参数的value值，并设置参数格式
            let data = {
                account:document.querySelector('.account').value,
                password:document.querySelector('.password').value
            }
            
            // 方法一：调用post请求方式
            // http.post('http://139.9.177.51:8099/users/add',data,function(res){
            //     if(res.status == 0){
            //         alert('注册成功！');
            //         location.href = './login.html'
            //     }else{
            //         alert('注册失败！')
            //     }
            // })

            // 方法二：使用万能方式调用
            http.ajxs(
                {
                    type:'post',
                    url:'http://139.9.177.51:8099/users/add',
                    data:data,
                    sucess:function(res){
                        if(res.status == 0){
                            alert('注册成功！');
                            location.href = './login.html'
                        }else{
                            alert('注册失败！')
                        }
                    }
                }
            );
        }

    </script>
</body>
</html>